import java.util.ArrayList;
import java.util.Scanner;

public class FindCycle {

    static ArrayList<Integer> trace = new ArrayList<Integer>();
    static boolean hasCycle = false;

    static int[][] graph = new int[26][26];
    final int pointNUm = 0;

    public static void main(String[] args) {

        // Scanner in = new Scanner(System.in);
        // String str = in.nextLine();

        String str = "B->A;B->D;C->B;C->E;D->C";

        String[] paths = str.split(";");
        String[] path;

        int row;
        int col;
        for (int i = 0; i < paths.length; i++) {
            path = paths[i].split("->");
            row = path[0].toCharArray()[0] - 'A';
            col = path[1].toCharArray()[0] - 'A';
            graph[row][col] = 1;

        }

        findCycle(0);
        if (!hasCycle)
            System.out.println("-");

        // in.close();

    }

    static void findCycle(int v) {
        int j = 0;
        if ((j = trace.indexOf(v)) != -1) {
            hasCycle = true;
            // System.out.print("Cycle:");
            while (j < trace.size()) {
                System.out.print((char) (trace.get(j) + 65));
                j++;
            }
            System.out.print("\n");
            return;
        }
        trace.add(v);

        for (int i = 0; i < 26; i++) {
            if (graph[v][i] == 1)
                findCycle(i);
        }
        trace.remove(trace.size() - 1);
    }

}

// https://www.cnblogs.com/dugujiujian/archive/2011/08/19/2146042.html